package ldk.util.adapterwrappers;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by ldkxingzhe@163.com on 2017/5/16.
 */
public class LoadMoreViewHolder extends RecyclerView.ViewHolder{

    protected View stateLoadingMoreView, stateNoMoreView, rootView;

    public static final int LOADING = 0;
    public static final int NO_MORE = 1;

    public LoadMoreViewHolder(View itemView){
        super(itemView);
        stateLoadingMoreView = itemView.findViewById(R.id.rl_state_loading);
        stateNoMoreView = itemView.findViewById(R.id.tv_no_more);
        rootView = itemView.findViewById(R.id.fl_root_view);
    }

    public LoadMoreViewHolder(ViewGroup parent){
        this(LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_load_more, parent, false));
    }

    public void setState(int state) {
        switch (state){
            case LOADING:
                stateNoMoreView.setVisibility(View.GONE);
                stateLoadingMoreView.setVisibility(View.VISIBLE);
                break;
            case NO_MORE:
                stateNoMoreView.setVisibility(View.VISIBLE);
                stateLoadingMoreView.setVisibility(View.GONE);
                break;
            default:
                throw new IllegalArgumentException("state is not right");
        }
    }
}